package com.njlime.sys.security;

/**
 * Created by Dean on 2017-7-28.
 */

import com.njlime.core.utils.StringUtil;
import org.apache.log4j.Logger;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

/**
 * Description: 告诉shiro如何验证加密密码，通过SimpleCredentialsMatcher或HashedCredentialsMatcher
 * @Author: Dean
 * @Version 1.0
 */

public class CustomCredentialsMatcher extends HashedCredentialsMatcher {
    private Logger logger = Logger.getLogger(getClass());
    @Override
    public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
        UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
        logger.debug(token.getOpenid());
        if(StringUtil.isEmpty(token.getOpenid())){
            return super.doCredentialsMatch(token, info);
        }else{
            if(info != null){
                return true;
            }
        }
        return false;
    }
}
